package com.xinan.weixin.media;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.sql.Timestamp;
import java.util.List;

@TableBind(tableName = "wx_articles")
public class WxArticles extends Model<WxArticles> {
    public static final WxArticles dao = new WxArticles();

    //columns START
    private String ID = "id";  //主键
    private String TITLE = "title";  //图文消息的标题
    private String AUTHOR = "author";  //图文消息的作者
    private String IMGS = "imgs";  //图文真实路径
    private String THUMBMEDIAID = "thumbMediaId";  //图文消息缩略图的media_id
    private String SHOWCOVERPIC = "showCoverPic";  //是否显示封面，1为显示，0为不显示
    private String DIGEST = "digest";  //图文消息的描述
    private String CONTENTSOURCEURL = "contentSourceUrl";  //在图文消息页面点击“阅读原文”后的页面
    private String MEDIAID = "mediaId";  //媒体文件/图文消息上传后获取的唯一标识
    private String CREATEDAT = "createdAt";  //媒体文件上传时间
    private String CONTENT = "content";  //媒体文件上传时间

    public void setId(int value) {
        set(ID, value);
    }

    public int getId() {
        return get(ID);
    }

    public void setTitle(String value) {
        set(TITLE, value);
    }

    public String getTitle() {
        return get(TITLE);
    }

    public void setAuthor(String value) {
        set(AUTHOR, value);
    }

    public String getAuthor() {
        return get(AUTHOR);
    }

    public void setImgs(String value) {
        set(IMGS, value);
    }

    public String getImgs() {
        return get(IMGS);
    }

    public void setThumbMediaId(String value) {
        set(THUMBMEDIAID, value);
    }

    public String getThumbMediaId() {
        return get(THUMBMEDIAID);
    }

    public void setShowCoverPic(String value) {
        set(SHOWCOVERPIC, value);
    }

    public String getShowCoverPic() {
        return get(SHOWCOVERPIC);
    }

    public void setDigest(String value) {
        set(DIGEST, value);
    }

    public String getDigest() {
        return get(DIGEST);
    }

    public void setContentSourceUrl(String value) {
        set(CONTENTSOURCEURL, value);
    }

    public String getContentSourceUrl() {
        return get(CONTENTSOURCEURL);
    }

    public void setMediaId(String value) {
        set(MEDIAID, value);
    }

    public String getMediaId() {
        return get(MEDIAID);
    }

    public void setCreatedAt(Timestamp value) {
        set(CREATEDAT, value);
    }

    public Timestamp getCreatedAt() {
        return get(CREATEDAT);
    }
    //columns END

    public List<WxArticles> findAll() {
        return find("select * from wx_articles");
    }

    /**
     * @param where
     * @return Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from wx_articles";
        if (StringKit.notBlank(where)) {
            sqlExp += " where " + where;
        }
        return Db.find("select * " + sqlExp);

    }

    public Page<WxArticles> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from wx_articles";
        if (StringKit.notBlank(where)) {
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select *", sqlExp);
    }

    public String getCONTENT() {
        return CONTENT;
    }

    public void setCONTENT(String CONTENT) {
        this.CONTENT = CONTENT;
    }
}

